/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.Usuario;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Andreina Wilhelm
 */
public class RegistrarSolicitanteForm extends org.apache.struts.action.ActionForm {

    private String correo;
    private String clave;

    public String getCorreo() {
        return correo;
    }

    public void setCorreo(String correo) {
        this.correo = correo.trim();
    }

    public String getClave() {
        return clave;
    }

    public void setClave(String clave) {
        this.clave = clave.trim();
    }

    
    /**
     *
     */
    public RegistrarSolicitanteForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    
    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        // Nueva instancia de ActionErrors
        ActionErrors errors = new ActionErrors();

        // validar campo de correo este lleno
        if (this.correo == null || this.correo.equals("")) {
            errors.add("err_correo", new ActionMessage("errors.required"));

        } // validar que correo siga formato
        else if (!this.correo.matches("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$")) {
            errors.add("err_correo", new ActionMessage("errors.formatoCorreo"));
        }

        // validar campo de clave esta lleno
        if (this.clave == null || this.clave.equals("")) {
            errors.add("err_clave", new ActionMessage("errors.required"));
        }

        return errors;
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset properties
        this.correo = "";
        this.clave = "";
    }
}
